<template>
	<el-dialog v-model="dialogShow" title="退款" width="600" :before-close="cancel">
		<EForm
			v-if="dialogShow"
			class="mr-10px"
			ref="dialogForm"
			:form-options="editOptions"
			form-label-width="120px"
			:form-rules="formRules"
			:form-data-current="dialogFormCurrent"
		>
		</EForm>
		<template #footer>
			<div class="dialog-footer">
				<el-button type="primary" @click="submit">确 认</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</template>
	</el-dialog>
</template>
<script setup>
import { editFormOptions, formRules } from './config';
import { ElMessage } from 'element-plus';
import EForm from '@/components/e-form';
import { useDict } from '/@/hooks/dict';
import { useUserInfo } from '/@/stores/userInfo';
import { bbOrderRefund } from '/@/api/insurance';

const emits = defineEmits(['success']);
const dialogShow = ref(false);
const dialogForm = ref(null);
const dialogFormCurrent = ref();

const { insurance_company } = useDict('insurance_company');

const editOptions = reactive(editFormOptions);

const { userInfos } = useUserInfo();


const show = async (data) => {
	dialogFormCurrent.value = {
		...data
	};
	dialogShow.value = true;
};
const closeDialog = () => {
	dialogShow.value = false;
};

const cancel = () => {
	closeDialog();
};

const submit = () => {
	dialogForm.value.handleValidate(async (valid) => {
		if (valid) {
			const { refundReason } = dialogForm.value.formData
			await bbOrderRefund({
				id: dialogFormCurrent.value.id, refundReason
			});
      cancel()
      emits('success')
		}
	});	
}

defineExpose({
	show,
});
</script>
